import React, { Component } from "react";

class Form extends Component {
  state = {
    textValue: "",
  };

  handleChange = (e) => {
    this.setState({
      textValue: e.target.value,
    });
  };

  handleKeyUp = (e) => {
    if (e.keyCode === 13 && this.state.textValue) {
      this.props.onGetItem(this.state.textValue);
      this.setState({
        textValue: "",
      });
    }
  };

  render() {
    return (
      <input
        type="text"
        value={this.state.textValue}
        onChange={this.handleChange}
        onKeyUp={this.handleKeyUp}
      />
    );
  }
}

export default Form;
